package com.whiteape.book.ui.adapter;

import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.whiteape.book.R;
import com.whiteape.book.core.manager.MediaStorageManager;
import com.whiteape.book.model.dto.SiteSourceBean;
import com.whiteape.book.model.dto.MediaChapterBean;
import com.whiteape.book.model.dto.MediaRecordBean;
import com.whiteape.book.model.type.MediaType;
import com.whiteape.book.model.type.RVLayoutType;

import java.util.ArrayList;
import java.util.List;

public class SiteSourceAdapter extends BaseQuickAdapter<SiteSourceBean, BaseViewHolder> {

    private List<SiteSourceBean> selectedList = new ArrayList<>();
    private RVLayoutType layoutType = RVLayoutType.LIST;
    private boolean selectedStateEnabled = false;

    public SiteSourceAdapter(int layoutResId, @Nullable List<SiteSourceBean> data) {
        super(layoutResId, data);
    }

    public void setSelectedList(List<SiteSourceBean> beanList) {
        selectedList = beanList;
    }

    public void setSelectedStateEnable(boolean enable) {
        selectedStateEnabled = enable;
    }

    @Override
    protected void convert(BaseViewHolder helper, SiteSourceBean item) {

        helper.setVisible(R.id.iv_select, selectedStateEnabled);
        if (selectedList.contains(item)) {
            helper.setImageResource(R.id.iv_select, R.mipmap.icon_mine_has_selected);
            ((ImageView)helper.getView(R.id.iv_select)).setColorFilter(mContext.getResources().getColor(R.color.colorAccent));
        } else {
            ((ImageView)helper.getView(R.id.iv_select)).clearColorFilter();
            helper.setImageResource(R.id.iv_select, R.mipmap.icon_mine_not_select);
        }
        helper.setText(R.id.tv_web_source_title, item.getSiteName());
        helper.setText(R.id.tv_web_source_author, "制作人: " + item.getCreator());
        helper.setText(R.id.tv_web_source_type, MediaType.getName(item.getSiteType()));
        helper.setBackgroundColor(R.id.tv_web_source_type, MediaType.getColorInt(item.getSiteType()));
        helper.setText(R.id.tv_web_source_desc,  "描述：" + item.getSiteDesc());
        Glide.with(mContext)
                .load(item.getSiteIconUrl())
                .placeholder(R.mipmap.no_cover_landscape)
                .fitCenter()
                .into((ImageView) helper.getView(R.id.iv_site_cover));

    }

}
